import unittest
from datetime import datetime

from django.test import TestCase
from backend.po.buy_order import BuyOrder
from backend.po.take_delivery import TakeDelivery
from backend.services import BuyOrderService
from backend.services import DeliveryService


class DeliverySvcTestCast(TestCase):
    def setUp(self):
        self.order_svc = BuyOrderService()
        self.delivery_svc = DeliveryService()

    def test_add_with_default_supplier_order(self):
        order = BuyOrder(buy_date_time=datetime.now(),
                         digest='buy lemon',
                         amount=1,
                         price=68.88,
                         unit='箱')

        delivery = self.delivery_svc.create(TakeDelivery(buy_order=order,
                                                         take_delivery_date_time=datetime.now(),
                                                         take_delivery_no='20240418000006'))

        self.assertEqual('20240418000006', delivery.take_delivery_no)
        self.assertIsNotNone(delivery.buy_order)
        self.assertEqual('buy lemon', delivery.buy_order.digest)
        self.assertIsNotNone(delivery.buy_order.supplier)
        self.assertEqual('System default supplier', delivery.buy_order.supplier.supplier_name)


if __name__ == '__main__':
    unittest.main(verbosity=2)
